<html>

    <?php
    echo $this->render("/common/header.phtml");
    ?>

    <script>        
        
        function updateBlock(BlockId){
            var baseUrl = <?php echo '"' . $this->update . '"' ?>   
            var lon =  document.getElementById('lon'+BlockId).value;
            var lat =  document.getElementById('lat'+BlockId).value;
            var txt =  document.getElementById('txt'+BlockId).value;
            txt = encodeURIComponent(txt);
            var a = baseUrl+"?lat="+lat+"&lon="+lon+"&description="+txt+"&id="+BlockId;
            ajax.get(a,null,function(f){
                alert(f);
            },null);            
        }

        function deleteBlock(BlockId){
            var baseUrl = <?php echo '"' . $this->delete . '"' ?>   
            var a = baseUrl+"?id="+BlockId;               
            ajax.get(a,null,function(f){
                alert(f);
            },null);            
        }
        
        function addBlock(){
            var baseUrl = <?php echo '"' . $this->add . '"' ?>   
            var lon =  document.getElementById('lon').value;
            var lat =  document.getElementById('lat').value;
            var txt =  document.getElementById('txt').value;
            txt = encodeURIComponent(txt);
            var a = baseUrl+"?lat="+lat+"&lon="+lon+"&description="+txt;        
            ajax.get(a,null,function(f){
                alert(f);
            },null);            
        }

    </script>

    <body>
        <?php
        echo $this->render("/common/topMenu.phtml");
        ?>
    <center>
        <div id="tbBlock" class="tbBlock" >
            <table border="0px" id="gradient-style">
                <tr>                   
                    <th>Lat</th>
                    <th>Lon</th>
                    <th>Description</th>
                    <th>Commit</th>
                </tr>
                <tr>                         
                    <th><input type="text" value="" name="lat" id="lat"/>      </th>
                    <th><input type="text" value="" name="lon" id ="lon"/>   </th>    
                    <th><TextArea id=txt></TextArea> </th>
                    <th><input type="submit" value="Add" onclick="addBlock()"/>  </th>
                </tr>                    
            </table>       



            <table border="0px" id="gradient-style">
                <?php
                echo "<tr>
                        <th>Block Id</th>
                        <th>Block Lon</th>
                        <th>Block Lat</th>
                        <th>Description</th>
                        <th>Update</th>
                        <th>Delete</th>
                      </tr>";
                foreach ($this->block as $data) {

                    echo '  <tr> ';
                    echo '      <td> ' . $data['id'] . '</td>';
                    echo '      <td>   <input type="text" value="' . $data['lon'] . '" id ="lon' . $data['id'] . '"/>  </td>';
                    echo '      <td>   <input type="text" value="' . $data['lat'] . '" id ="lat' . $data['id'] . '"/> </td>';
                    echo '      <td> <TextArea id=txt' . $data['id'] . '>' . $data['description'] . '</TextArea>  </td>';
                    echo '      <td> <input type="submit" onclick="updateBlock(' . $data['id'] . ') " value="Update" /></td>';
                    echo '      <td> <input type="submit" onclick="deleteBlock(' . $data['id'] . ') " value="Delete" /></td>';
                    echo '  </tr> ';
                }
                ?>
            </table>

        </div>
    </center>
</body>

</html>
